import {useUserStore} from "~/stores/user-store";
import {ANONYMOUS, ROUTE_INDEX, ROUTE_MAIN} from "~/resource/constants/common/constant";


export default defineNuxtRouteMiddleware((to, from) => {
    const userStore = useUserStore();
    //未登录的不能允许跳转到除匿名路径以外的路径
    if ((ROUTE_INDEX !==  to.path && !to.path.startsWith(ANONYMOUS)) && !userStore.isAuthentication) {
        return navigateTo(ROUTE_INDEX);
    }
    //已经登录的不允许跳转到登录页
    if (ROUTE_INDEX ===  to.path && userStore.isAuthentication) {
        return navigateTo(ROUTE_MAIN);
    }
})